# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=nmap
pkgver=7.95
pkgrel=1
pkgdesc="network exploration tool and security/port scanner"
url="https://nmap.org"
arch="all"
license="custom"
makedepends="
	autoconf
	automake
	libtool
	libpcap-dev
	libssh2-dev
	linux-headers
	lua5.4-dev
	openssl-dev
	pcre-dev
	zlib-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-scripts::noarch
	$pkgname-nselibs::noarch
	$pkgname-nping
	$pkgname-ncat
	"
options="net" # needed for test suite
source="https://nmap.org/dist/nmap-$pkgver.tar.bz2
	fortify-source.patch"

# secfixes:
#   7.80-r0:
#     - CVE-2017-18594
#     - CVE-2018-15173

prepare() {
	default_prepare
	update_config_sub

	autoreconf libpcre libdnet-stripped -ivf
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--without-zenmap \
		--with-openssl=yes \
		--with-libpcap=yes \
		--with-libpcre=yes \
		--with-libz=yes \
		--with-libssh2=yes \
		--with-liblua=/usr/lua5.4
	make
}

check() {
	make check
}

package() {
	make -j1 DESTDIR="$pkgdir" install
}

scripts() {
	depends="$pkgname-nselibs"
	pkgdesc="$pkgdesc (scripts)"
	amove usr/share/nmap/scripts
}

nselibs() {
	pkgdesc="$pkgdesc (nselibs)"
	amove usr/share/nmap/nse_main.lua
	amove usr/share/nmap/nselib
}

ncat() {
	pkgdesc="$pkgdesc (ncat tool)"
	amove usr/bin/ncat
}

nping() {
	pkgdesc="$pkgdesc (nping tool)"
	amove usr/bin/nping
}

sha512sums="
fd95a8bc627a2b8b507353f761dc9fdc8e880a0dd2d75a51b9cb3ec664318796af9bb16a6ff9a1358bd77ad669c2a54e333be630f201f69287692a7d2d41c17e  nmap-7.95.tar.bz2
2d1f6e290723ac643f456a0e1ac95c4c966106cf2ab743839d25c835bf0141dc2d6bfee19285c3518d4c5f553b0505dabe5a496b769ba47b7adb03e791f05b8d  fortify-source.patch
"
